var appDailyReminder = new Vue({
  el: "#kefu_remind",
  data: {
    filterForm: {
      event_type: "",
      company_name: "",
      contact_name: "",
    },
    infoTable: {
      list: [],
      total: 0,
      pageNumber: 1,
      pageSize: 10,
      loading: false,
    },
    eventTypeList: [],
  },
  mounted() {},
  methods: {
    init() {
      this.getEventTypeList();
      this.getInfoList("init");
    },
    // 获取事件类型列表
    getEventTypeList() {
      apiGetEventTypeListIcon()
        .then((res) => {
          this.eventTypeList = res.data;
        })
        .catch((err) => {
          this.$message.error(err && err.msg);
        });
    },
    // 获取列表
    getInfoList(type) {
      if (type !== "init") {
        this.infoTable.pageNumber = 1;
      }
      this.infoTable.loading = true;
      const sendDate = apiGetInfoListIcon({
        pageNumber: this.infoTable.pageNumber,
        pageSize: this.infoTable.pageSize,
        ...this.formatFilterForm(),
      })
        .then((res) => {
          const { data, total } = res;
          this.infoTable.list = data;
          this.infoTable.total = total;
          this.infoTable.loading = false;
          this.$refs.infoTable.doLayout();
        })
        .catch((err) => {
          this.infoTable.list = [];
          this.infoTable.total = 0;
          this.infoTable.loading = false;
          this.$message.error(err && err.msg);
        });
    },
    // 格式化筛选表单
    formatFilterForm() {
      console.log("formatFilterForm:", this.filterForm);
      const form = {};
      const list = [];
      for (const key in this.filterForm) {
        if (!list.includes(key)) {
          form[key] = this.filterForm[key];
        }
      }

      return form;
    },
    // 重置筛选表单
    resetfilterForm() {
      this.$refs.filterFormRef.resetFields();
      this.filterForm = {
        event_type: "",
        company_name: "",
        contact_name: "",
      };
      this.getInfoList();
    },
    // 每页数
    sizeChangeHandle(table, val) {
      this.infoTable.pageSize = val;
      this.infoTable.pageNumber = 1;
      this.getInfoList("init");
    },
    // 当前页
    currentChangeHandle(table, val) {
      this.infoTable.pageNumber = val;
      this.getInfoList("init");
    },
  },
});
